package com.itkjb.leisurely.center.support;

import com.itkjb.leisurely.center.sys.model.SysUserDetail;
import com.itkjb.leisurely.core.base.BaseConstantsEnum;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.HashMap;
import java.util.Map;

/**
 * Copyright (C), 2018-2099
 * FileName: BaseJwtTokenEnhancer
 * @Author: lix
 * @Date: 2019-05-17 14:45
 * @Description: 基础的token 增强
 * @Version: V1.0.0
 */
public class CenterJwtTokenEnhancer implements TokenEnhancer {

    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        Map<String, Object> info = new HashMap<>();
        /*if(authentication.getOAuth2Request() != null){
            info.put("clientId",authentication.getOAuth2Request().getClientId());
        }*/
        info.put("code", BaseConstantsEnum.HTTP_SUCCESS.getCode()+"");
        info.put("msg", "success");
        SysUserDetail userDetail = (SysUserDetail)authentication.getUserAuthentication().getPrincipal();
        info.put("project", userDetail.getUserId());
        info.put("timestamp",System.currentTimeMillis()+"");
        ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(info);
        return accessToken;
    }
}
